﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TireService.Data;

namespace TireService.Website.Kunde
{
    public partial class Historik : System.Web.UI.Page
    {
        #region Public Properties

        public int CustomerId
        {
            get
            {
                if (ViewState["_customerid"] != null)
                    return (int)ViewState["_customerid"];
                else
                    return (int)Session["CustomerId"];
            }
            set
            {
                ViewState["_customerid"] = value;
            }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            TireServiceDB db = new TireServiceDB();

            if (Page.IsPostBack != true)
            {

            }

            BindCustomerEmailLog(db, this.CustomerId);
        }

        /// <summary>
        /// Function that bind customer email log data to gridview
        /// </summary>
        /// <param name="db">Connection to database</param>
        /// <param name="CustomerId">Id on customer</param>
        private void BindCustomerEmailLog(TireServiceDB db, int CustomerId)
        {
            gvCustomerEmailLog.DataSource = db.GetCustomerBusinessEmailLogs(CustomerId, false);
            gvCustomerEmailLog.DataBind();
        }

        /// <summary>
        /// Postback function that binds customer logs gridview
        /// </summary>
        protected void gvCustomerEmailLog_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
        {
            TireServiceDB db = new TireServiceDB();

            BindCustomerEmailLog(db, this.CustomerId);
        }
    }
}